import { DataSource, DatabaseType, getCreateTableFormSchema } from '@/services';
import { createGetFormSchema } from '@/services/g01';
import type {
    ProFormColumnsType,
    ProFormLayoutType,
} from '@ant-design/pro-components';
import { BetaSchemaForm, ProFormSelect } from '@ant-design/pro-components';
import { Alert, DatePicker, Space } from 'antd';
import dayjs from 'dayjs';
import { ReactNode, useEffect, useState } from 'react';

export const UpateTableForm = (props: {
    databaseType: DatabaseType, triggerNode?: JSX.Element | undefined,
    layoutType: ProFormLayoutType, onSave: (item: any) => Promise<any>
}) => {

    const [columns, setColumns] = useState<ProFormColumnsType<any>[]>([]);

    useEffect(() => {
        getCreateTableFormSchema(props.databaseType).then((schema) => {
            setColumns(schema);
        }).catch((err) => {
            console.log(err);
        });
    }, [props.databaseType]);

    return (
        <BetaSchemaForm<any>
            trigger={props.triggerNode}
            layoutType={props.layoutType}
            steps={[
                {
                    title: 'ProComponent',
                },
            ]}
            rowProps={{
                gutter: [16, 16],
            }}
            colProps={{
                span: 12,
            }}
            grid={props.layoutType !== 'LightFilter' && props.layoutType !== 'QueryFilter'}
            onFinish={async (values) => {
                console.log(values);
                props.onSave(values);
            }}
            columns={(props.layoutType === 'StepsForm' ? [columns] : columns) as any}
        />
    );
};

export default UpateTableForm;
